<!-- 确认订单 -->
<template>
  <u-popup v-model="show" mode="bottom" border-radius="14" @maskClick="_close">
    <view class="configOrder">
      <view class="justify-between headTitle">
        <view></view>
        <view class="fz-14">确认订单</view>
        <view @click.stop="_close"><u-icon name="close" size="28" /></view>
      </view>
      <!-- 虚拟商品 -->
      <view class="px32 fictitious_box" v-if="goodsData&&goodsData.freightType==2">
        <u-field required :border-bottom="false" v-model="receiveName" maxlength="30" label="联系人" placeholder="请填写你的名字" />
        <u-field required :border-bottom="false" v-model="receiveMobile"  maxlength="12" label="手机号" placeholder="请填写你的手机号" />
      </view>
      <!-- 其他商品 -->
      <!-- 无默认地址 -->
      <view class="addressBox px32" v-if="goodsData&&(goodsData.freightType==1 || goodsData.freightType==3)&&(!choiceAddressData || !choiceAddressData.id)" @click.stop="gotoAddress(1)">
        <div class="not_address_box">
          <i class="iconfont icon-tianjia"></i>
          <span>请添加收货地址</span>
        </div>
        <i class="iconfont icon-arrow_right"></i>
      </view>
      <!-- 有默认地址 -->
      <view class="addressBox px32" v-if="goodsData&&(goodsData.freightType==1 || goodsData.freightType==3)&&choiceAddressData.id" @click.stop="gotoAddress(2)">
        <div class="addressBox_l"><i class="iconfont icon-address"></i></div>
        <div class="addressBox_r">
          <div class="addressBox_r_top">{{choiceAddressData.name}}  {{mobileStrFn(choiceAddressData.mobile)}}  {{choiceAddressData.provinceName}}  {{choiceAddressData.cityName}}  {{choiceAddressData.countyName}}</div>
          <div class="addressBox_r_bot" v-if="choiceAddressData.addr">{{choiceAddressData.addr}}</div>
          <view class="u-p-t-16 fz-12" style="color:#FB9551;" v-if="freightObj.freight === -1">超出配送范围，换个地址吧~</view>
        </div>
        <i class="iconfont icon-arrow_right"></i>
      </view>
      <!-- 商品信息+商品规格 -->
      <view class="goodsBox_two">
        <view class="u-flex u-p-b-20 u-p-t-20">
          <view class="goodsImg">
            <image class="img_box" :src="selectSpecsImages || goodsData.mainImage" mode="aspectFill" @click.stop="imgUrlPreviewFn(selectSpecsImages || goodsData.mainImage)"/>
            <!-- <view class="times" v-if="goodsEndTiem">{{goodsEndTiem}}</view> -->
          </view>
          <view class="goodsMsg">
            <div>
            <view v-if="goodsSkuSamplePrice>0">
              <view class="fz-18 fw6 themeFontColor items-center">
              <text class="u-p-r-20" v-if="goodsNum>1">{{goodsNum}}件</text>
                <text>供货价购样</text>
                <text>￥{{_calculateGoodsPlice(goodsSkuSamplePrice,goodsNum)}}</text>
              </view>
              <view class="fz-12 viceColor">
                团购价￥{{_calculateGoodsPlice(goodsData.minSalePrice,goodsNum)}}
              </view>
            </view>
            <view class="fz-18 fw6 themeFontColor items-center" v-else-if="goodsData.minSalePrice>0">
              <text class="u-p-r-20" v-if="goodsNum>1">{{goodsNum}}件</text>
              <text>￥{{_calculateGoodsPlice(goodsData.minSalePrice,goodsNum)}}</text>
            </view>

            <view class="fz-12 specs_box color9" :class="{'u-m-t-0': goodsSkuSamplePrice > 0}" v-if="selectSpecName">
              <view class="select_tit_box">已选择：</view>
              <view class="specs_name_box line_clamp">{{nameStrFn(selectSpecName)}}</view>
            </view>
            </div>
            <view class="zidingyi">
              <u-number-box v-model="goodsNum" :disabled="totalInventory<1" :max="99" :step="1" :min="1" :size="24"></u-number-box>
            </view>
          </view>
        </view>
      </view>
      <view class="goodsBox_two justify-between items-center linh-48" v-if="freightObj.freight !== -1">
        <view>
          <text>运费</text>
          <text class="viceColor u-p-l-20" v-if="freightObj.conditionMoney">(还差{{freightObj.conditionMoney - totalPlice}}元可包邮)</text>
          <text class="viceColor u-p-l-20" v-if="freightObj.conditionNumber">(还差{{freightObj.conditionNumber - goodsNum}}件可包邮)</text>
        </view>
        <view>{{!freightObj.freight ? '包邮' : `￥${freightObj.freight}`}}</view>
      </view>

      <scroll-view class="goodsBox" scroll-y="true" -webkit-overflow-scrolling="touch" scroll-with-animation="true">
        <view class="goodsScpe color9" v-if="goodsSpecsList.length>0">
          <view v-for="(item,index) in goodsSpecsList" :key="index" class="forBox u-m-b-32">
            <view>{{item.specName}}</view>
            <view class="u-flex scpeBox_con">
              <button
              v-for="(scpe,idx) in item.goodsSpecValuesVOList"
              :key="idx" class="scpeBox fz-12"
              :class="{'acitveScpe': selectSpecsNameArr.includes(scpe.specValue)&&totalInventory>0&&scpe.quantity>0,'scpeBox_dis': !scpe.quantity||scpe.quantity<1}"
              :disabled="!scpe.quantity||scpe.quantity<1"
              @click.stop="colorListClick(scpe,index,idx)">
              {{scpe.specValue}}
              </button>
            </view>
          </view>
        </view>
        <!-- 备注 -->
        <view class="remarkBox">
          <view class="fz-16 u-m-r-32">备注：</view>
          <input style="flex:1" v-model="remark" maxlength="100" placeholder="请输入您需要备注的内容" />
        </view>
      </scroll-view>
      <view class="followGroupBox"></view>
      <view class="followGroup_btn_box">
        <button class="btn_box" v-if="totalInventory>0" :class="{'btn_box_dis':followDisabledBtn}" :disabled="followDisabledBtn" @click.stop="followGroupFn">
          {{goodsSkuSamplePrice>0?'供货价购样':'立即抢购'}}
          <i v-if="!followDisabledBtn">￥{{freightObj.freight && freightObj.freight > 0 ? _calculateGoodsPlice(goodsSkuSamplePrice || goodsData.minSalePrice,goodsNum,3) + freightObj.freight : _calculateGoodsPlice(goodsSkuSamplePrice || goodsData.minSalePrice,goodsNum,3)}}</i>
        </button>
        <view class="btn_box sold_out_box" v-else>已卖完</view>
      </view>
    </view>
    <CancelPayment
    :show="cancelPaymentType"
    :isTime="isTime"
    :paymentTime="paymentTime"
    @placeAnOrderTwoFn="placeAnOrderTwoFn"
    @giveUpFn="giveUpFn"
    @closePaymentFn="closePaymentFn"
    @reOrderFn="reOrderFn"
    />
  </u-popup>
</template>

<script>
import goods from "@/api/goods.js";
import Util from "@/api/util.js"
import user from "@/api/user.js";
import orderApi from "@/api/orderApi.js";
import { numSub,numMulti,numDiv } from "@/utils/calculate.js";
import CancelPayment from "./cancelPayment.vue"; // 拒绝支付
export default {
  props:{
    show: {
      type: Boolean,
      default: false,
    },
    videoItem: {
      type: Object,
      default: {}
    },
    goodsSpu: {
      type: Number|String,
      default: ''
    },
    dynamicId: {
      type: Number|String,
      default: ''
    },
    shopWindowId: {
      type: Number|String,
      default: ''
    },
    // 结束时间
    // goodsEndTiem: {
    //   type: String,
    //   default: ''
    // },
  },
  components: {
    CancelPayment
  },
  data(){
    return {
      goodsNum: 1,
      remark: '',
      receiveName: '',
      receiveMobile: '',
      goodsData: {
        minSalePrice: 0.00,
        maxSalePrice: 0.00,
      },
      goodsSpecsList: [], // 规格数据
      selectSpecsArr: [], // 选择的规格
      selectSpecsNameArr: [], // 已选规格名称
      selectSpecName: '', // 选择规格的名字
      selectSpecsListIndex: [], // 选择规格下标
      followDisabledBtn: true,
      goodsSkuId: '', // 商品的skuID
      goodsSkuSamplePrice: 0, // 商品的购样价
      orderIdStr: '', // 下单订单号
      payRecordId: '', // 支付单号
      timer: null, // 查询用户支付状态定时器
      cancelPaymentType: false, // 取消支付弹窗
      paymentTime: 300000, // 取消支付倒计时时间（毫秒）
      isTime: true, // 是否刷新取消支付倒计时定时器
      totalInventory: 0, // 当前商品的总库存
      counterDisabled: false, // 没有库存禁止添加
      selectSpecsImages: '', // 选择规格图片
      
      // 运费对象 运费为-1则是
      freightObj: {},
      totalPlice: 0,  //当前商品总价
    }
  },
  watch: {
    show(nVal){
      if(nVal){
        this.queryGoodsFn()
        this.defaultAddressFn()
      }else{
        this.initFn() // 关闭弹窗初始化页面数据
      }
    },
    choiceAddressData(nval,oval){
      console.log('地址变化');
      this._calculateFreightPlice()
    },
    totalPlice(nval,oval){
      console.log('价格变化');
      this._calculateFreightPlice()
    }
  },
  computed: {
    choiceAddressData () {
      return this.$store.state.choiceAddressData
    }
  },
  methods:{
    initFn () {
      this.goodsData = {
        minSalePrice: 0.00,
        maxSalePrice: 0.00,
      }
      this.goodsSpecsList = []
      this.selectSpecsArr = []
      this.selectSpecsNameArr = []
      this.selectSpecsListIndex = []
      this.followDisabledBtn = true
      this.goodsSkuId = ''
      this.goodsSkuSamplePrice = 0
      this.paymentTime = 300000
      this.cancelPaymentType = false
      this.isTime = true
    },
    nameStrFn (str) {
      let strData = str
      if (!strData) return
      return strData.replace('^^','/')
    },
    // 重新下单
    reOrderFn () {
      this.cancelPaymentType = false
    },
    closePaymentFn () {  // 关闭取消支付弹窗
      this.cancelPaymentType = false
      this._close() // 关闭当前弹窗
    },
    // 拒绝支付
    giveUpFn () {
      this.closePaymentFn()
      this.navigateTo({ url: `/pagesA/order/myOrderDetails?orderAllId=${this.orderIdStr}` })
    },
    // 继续支付
    placeAnOrderTwoFn () {
      this.cancelPaymentType = false
      this.isTime = false
      this.weiXinPayFn(this.orderIdStr)
    },
    // 跟团
    followGroupFn () {
      let this_ = this
      if (this_.goodsData.freightType==2) {
        if (!this_.receiveName) {
          return wx.showToast({
            title: '请填写你的名字！',
            icon: "none",
            duration: 1500
          })
        }
        if (!this_.receiveMobile) {
          return wx.showToast({
            title: '请填写你的手机号!',
            icon: "none",
            duration: 1500
          })
        }
      }
      let receivingData = uni.getStorageSync('receivingData')
      receivingData = { // 把虚拟物品收货信息存用户信息缓存
        ...receivingData,
        receiveName: this_.receiveName,
        receiveMobile: this_.receiveMobile,
      }
      uni.setStorageSync('receivingData', receivingData)
      if ((this_.goodsData.freightType == 1 || this_.goodsData.freightType == 3) && !this_.choiceAddressData) {
        return wx.showModal({
          title: '',
          content: '你还没有收货地址，请点击添加',
          confirmText: '添加',
          confirmColor: '#E44435',
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
              this_.gotoAddress(1)
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }else if((this_.goodsData.freightType == 1 || this_.goodsData.freightType == 3) && this_.freightObj.freight === -1){
        return uni.showToast({
          title: '收货地址超出配送范围，请修改地址',
          icon: "none",
          duration: 1500
        })
      }
      wx.showModal({
        title: '',
        content: '支付后资金将直接进入对方账户，请确认对方信息后支付',
        confirmText: '去支付',
        confirmColor: '#E44435',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            this_.placeOrderFn()
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    // 下订单
    placeOrderFn () {
      let params = {
        buyNum: this.goodsNum,
        dynamicId: this.videoItem.dynamicId || '', // 有可能不存在，不存在传空
        shopWindowId: this.shopWindowId,
        skuId: this.goodsSkuId,
        totalSalePrice: this._calculateGoodsPlice(this.goodsSkuSamplePrice || this.goodsData.minSalePrice,this.goodsNum),
        type: this.goodsSkuSamplePrice ? 2 : 1
      }
      if (this.goodsData.freightType==2) {
        params = {
          ...params,
          receiveMobile: this.receiveMobile,
          receiveName: this.receiveName
        }
      }
      if (this.goodsData.freightType==1 || this.goodsData.freightType==3) {
        params = {
          ...params,
          userAddressId: this.choiceAddressData.id
        }
      }
      orderApi.submitOrder(params).then(res => {
        if (res.code == 200) {
           this.orderIdStr = res.data.orderId
           this.isTime = true // 下单刷新倒计时定时器
           this.weiXinPayFn(this.orderIdStr)
        }
      })
    },
    // 获取单号微信支付
    async weiXinPayFn (id) {
      let _this = this
      orderApi.payTrade({orderAllId:id}).then(res => {
        if (res.code == 200) {
          wx.showLoading({
            title: '支付中'
          })
          _this.payRecordId = res.data.outTradeNo
          let payRes = res.data.weChatRespVO
          wx.requestPayment({
            timeStamp: payRes.timeStamp,
            nonceStr: payRes.nonceStr,
            package: payRes.packageInfo,
            signType: payRes.signType,
            paySign: payRes.paySign,
            success (res_) {
              console.log(res_,'支付')
              if (res_.errMsg == 'requestPayment:ok') {
                // if (_this.timer) clearInterval(_this.timer)
                // _this.closePaymentFn() // 关闭弹窗
                // _this.$emit('paySuccessFn',_this.orderIdStr)
                wx.hideLoading()
              }
            },
            fail (res_) {
              console.log(res_,'取消')
              if (res_.errMsg == 'requestPayment:fail cancel') {
              }
              if (_this.timer) clearInterval(_this.timer)
              _this.cancelPaymentType = true
              wx.hideLoading()
            }
          })
          _this.timer = setInterval(()=>{
            _this.paystatusFn()
          },1500)
        }
      })
    },
    // 查询微信支付状态
    async paystatusFn () {
      orderApi.queryPayStatus({outTradeNo: this.payRecordId}).then(res => {
        if (res.code == 200&&res.data.status==2) {
          wx.hideLoading()
          if (this.videoItem.followStatus!=1) { // 下单用户没关注当前视频作者逻辑
            this.videoItem = { // 先修改当前下单视频的关注值
              ...this.videoItem,
              followStatus: 1,
            }
            this.$store.commit('FOLLOW_TYPE', this.videoItem) // 调用公用关注方法遍历当前作者其他的视频修改关注值
          }
          if (this.timer) clearInterval(this.timer)
          this.closePaymentFn() // 关闭弹窗
          this.$emit('paySuccessFn',this.orderIdStr)
        }
      })
    },
    // 查询默认地址
    defaultAddressFn () {
      user.defaultAddress({}).then(res => {
        if (res.code == 200) {
          this.$store.commit("CHOICE_ADDRESS_DATA",res.data)
        }
      })
    },
    // 获取选择规格项
    getSpecsFn (data, skuName) {
      let data_ = data
      let skuNameArr = skuName.split('^^')
      if (data_.goodsSpecificationVOList&&data_.goodsSpecificationVOList.length>0) {
        this.goodsSpecsList = data_.goodsSpecificationVOList
        let skuIndex = 0
        this.goodsSpecsList[0].goodsSpecValuesVOList.forEach((goods,i)=>{
          if (goods.specValue == skuNameArr[0]) skuIndex = i // 判断有库存的第一个规格名称是否相同获取下标值
        })
        this.firstStockFn() // 获取第一个spu下的sku库存
        if (this.totalInventory>0) this.colorListClick(this.goodsSpecsList[0].goodsSpecValuesVOList[skuIndex],0) // 总库存大于0默认选中第一个规格
      }
    },
    // 点击选择规格处理逻辑
    colorListClick(item, index) {
      console.log(index,item.quantity,(index==0&&item.quantity<1))
      if (this.totalInventory<1||(index==0&&item.quantity<1)) return // 总库存小于1禁止选规格或者选择的第一个spu里面的sku没库存
      let addType = true
      if (this.selectSpecsArr.length>0&&this.selectSpecsArr[index]&&this.selectSpecsArr[index].id==item.id) addType = false
      if (!addType) return // 选择是同个规格不走下面逻辑1.43版本修改
      if (this.selectSpecsListIndex.length>0&&this.selectSpecsListIndex.includes(index)) {
        let indexStr = 0
        this.selectSpecsListIndex.forEach ((isp, i)=>{
          if (isp == index) {
            indexStr = i
          }
        })
        this.selectSpecsListIndex.splice(indexStr, 1)
        this.selectSpecsArr.splice(indexStr, 1)
      }
      if (addType) { // 要是点击是相同的就不添加
        if (index == 0) {
          this.selectSpecsArr.unshift(item);
          this.selectSpecsListIndex.unshift(index)
        } else {
          this.selectSpecsArr.push(item);
          this.selectSpecsListIndex.push(index)
        }
      }
      if (this.selectSpecsArr.length>0) { // 选择的规格要大于0进入计算取值
        let salePriceArr = []
        let selectSpecsNameStr = []
        this.selectSpecsArr.forEach((item,i) => {
          selectSpecsNameStr.push(item.specValue)
        })
       selectSpecsNameStr=selectSpecsNameStr.join('^^')
        this.goodsData.goodsSkuDetailsVOList.forEach((goods,j) => {
          if (this.selectSpecsArr.length == this.goodsData.goodsSpecificationVOList.length) { // 选择的规格和实际规格项目长度是一样取值
            if (selectSpecsNameStr == goods.specValue) {
              salePriceArr.push(goods.salePrice)
              this.goodsSkuId = goods.id
              this.goodsSkuSamplePrice = goods.samplePrice
            }
          } else {  // else不一样取值
            let specValueStr = goods.specValue.split('^^')
            if (specValueStr.includes(selectSpecsNameStr)) {
              salePriceArr.push(goods.salePrice)
            }
          }
        })
        this.goodsData = {  // 取出已选规格最高和最低价格，方便显示和对比
          ...this.goodsData,
          maxSalePrice: Util.getMaximin(salePriceArr,'max'),
          minSalePrice: Util.getMaximin(salePriceArr,'min')
        }
      } else { // 没选中规格
        let salePriceArr = []
        this.goodsData.goodsSkuDetailsVOList.forEach((goods,j) => {
          salePriceArr.push(goods.salePrice)
        })
        this.goodsData = {
          ...this.goodsData,
          maxSalePrice: Util.getMaximin(salePriceArr,'max'),
          minSalePrice: Util.getMaximin(salePriceArr,'min')
        }
      }
      if (this.selectSpecsArr.length == this.goodsData.goodsSpecificationVOList.length) { // 选择的规格类型和应该选择的一样长度，跟团按钮可点击
        this.followDisabledBtn = false
      } else {
        this.followDisabledBtn = true
      }
      let selectSpecNameArr = []
      this.selectSpecsArr.forEach((item,i)=>{
        selectSpecNameArr.push(item.specValue)
      })
      this.selectSpecsNameArr = selectSpecNameArr // 选中的规格名称
      // 当spu个数大于2个并且是点击第一个spu里面的sku的时候走计算第2个spu里面sku库存数，目前spu最多2个
      if (this.goodsData.goodsSpecificationVOList.length>1&&index==0) this.countSStockFn(selectSpecNameArr,index)
      this.selectSpecName = selectSpecNameArr.join('^^')
      this.$forceUpdate()
      this.goodsData.goodsSkuDetailsVOList.forEach((goods,i) => { // 获取选择规格的图片
        if (goods.specValue == this.selectSpecName) {
          this.selectSpecsImages = goods.images?goods.images:''
        }
      })
    },
    // 计算一级规格库存
    firstStockFn () {
      this.goodsData.goodsSkuDetailsVOList.forEach((goods,i) => {
        this.goodsData.goodsSpecificationVOList[0].goodsSpecValuesVOList.forEach((spuData,j)=>{
          if (this.goodsData.goodsSpecificationVOList.length == 1) { // 一个大规格spu
            if (goods.specValue==spuData.specValue) {
              this.selectSpecsImages = goods.images?goods.images:''
              this.goodsSpecsList[0].goodsSpecValuesVOList[j] = {
                ...this.goodsSpecsList[0].goodsSpecValuesVOList[j],
                quantity: Number(goods.quantity)
              }
            }
          }
          if (this.goodsData.goodsSpecificationVOList.length == 2) { // 2个大规格的时候
            let specValueArr = goods.specValue.split('^^')
            if (specValueArr[0]==spuData.specValue) {
              this.selectSpecsImages = goods.images?goods.images:''
              this.goodsSpecsList[0].goodsSpecValuesVOList[j] = {
                ...this.goodsSpecsList[0].goodsSpecValuesVOList[j],
                quantity: this.goodsSpecsList[0].goodsSpecValuesVOList[j].quantity>0?Number(this.goodsSpecsList[0].goodsSpecValuesVOList[j].quantity) + Number(goods.quantity):Number(goods.quantity)
              }
            }
          }
        })
      })
    },
    // 处理规格库存数据
    countSStockFn (nameArr,index) {
      const nameArrName = nameArr
      let nameArrStr = nameArr[0]
      if (index==0) { // 表示点击的是第一个spu里面的sku计算第个spu下sku的库存
        this.goodsData.goodsSkuDetailsVOList.forEach((goods,i) => {
          this.goodsData.goodsSpecificationVOList[1].goodsSpecValuesVOList.forEach((spuData,j)=>{
            if (goods.specValue == `${nameArrStr}^^${spuData.specValue}`) {
              this.goodsSpecsList[1].goodsSpecValuesVOList[j] = {
                ...this.goodsSpecsList[1].goodsSpecValuesVOList[j],
                quantity: goods.quantity
              }
               // 当前选中的规格在切换第一个spu下的sku没库存的时候需要去掉选中的状态
              if ((goods.specValue == nameArrName.join('^^'))&&goods.quantity<1&&nameArrName[1]==spuData.specValue) {
                this.selectSpecsNameArr.splice(1,1)
                this.selectSpecName = this.selectSpecsNameArr.join('^^')
                this.selectSpecsArr.splice(1,1)
                this.selectSpecsListIndex.splice(1,1)
                this.followDisabledBtn = true
              }
            }
          })
        })
      }
    },
    // 查询商品信息
    queryGoodsFn () {
      goods.getByGoodsDetails({shopWindowId: this.shopWindowId}).then(res=>{
        if (res.code == 200) {
          this.goodsData = res.data
          let salePriceArr = []
          let skuName = '' // 默认选中的规格的名称
          this.goodsData.goodsSkuDetailsVOList.forEach((goods,j) => {
            salePriceArr.push(goods.salePrice)
            this.totalInventory = Number(this.totalInventory) + Number(goods.quantity)
            if (Number(goods.quantity)>0&&!skuName){
              skuName = goods.specValue // 获取第一个有库存的规格组合方便默认选中
            }
            if (Number(goods.quantity)>0&&!this.goodsSkuSamplePrice){
              this.goodsSkuSamplePrice = goods.samplePrice // 获取第一个有库存的购样价
            }
          })
          this.goodsData = {
            ...this.goodsData,
            images: JSON.parse(this.goodsData.images),
            maxSalePrice: Util.getMaximin(salePriceArr,'max'),
            minSalePrice: Util.getMaximin(salePriceArr,'min')
          }
          if (!this.goodsData.goodsSpecificationVOList || this.goodsData.goodsSpecificationVOList.length<1) { // 默认规格商品逻辑
            this.followDisabledBtn = false
            this.goodsSkuId = this.goodsData.goodsSkuDetailsVOList[0].id
            this.goodsSkuSamplePrice = this.goodsData.goodsSkuDetailsVOList[0].samplePrice
          }
          this.followDisabledBtn = this.totalInventory < 1? true : false // 总库存小于1禁止购买
          this.getSpecsFn(this.goodsData,skuName) // 获取规格处理方法
        }
        let receivingData = uni.getStorageSync('receivingData')//获取下用户信息里面有没虚拟收货信息
        this.receiveName = receivingData.receiveName?receivingData.receiveName:''
        this.receiveMobile = receivingData.receiveMobile?receivingData.receiveMobile:''
      })
    },
    // 关闭当前弹窗
    _close(){
      this.$emit('close')
    },
    // 更换添加地址
    gotoAddress (type) {
      if (type==1) {
        this.navigateTo({ url: '/pagesB/addressLibrary/addAddress' })
      } else {
        this.navigateTo({ url: `/pagesB/addressLibrary/index?type=2&spuId=${this.goodsData.spuId}` })
      }
    },
    // 处理电话号码*号
    mobileStrFn (str) {
      return Util.mobileStr(str)
    },
    // // 计算商品总价
    _calculateGoodsPlice(goodsPlice,num,type){
      if(type === 3){this.totalPlice = numMulti(goodsPlice,num,2)}
      return numMulti(goodsPlice,num,2)
    },
    // 运费计算
    _calculateFreightPlice(){
      if(!this.goodsData.spuId || !this.goodsNum) return
      let params = {
         cityVO: {
            cityId: this.choiceAddressData.cityId, // 市id
            provinceId: this.choiceAddressData.provinceId // 省编码
         },
         count: this.goodsNum, // 购买件数
         payPrice: this._calculateGoodsPlice(this.goodsSkuSamplePrice || this.goodsData.minSalePrice,this.goodsNum), // 支付金额
         spuId: this.goodsData.spuId // SPUID
      } 
      orderApi.getFreightPlice(params).then(res=>{
        this.freightObj = res.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.configOrder{
  background: #F7F8FA;
  min-height: 70vh;
  max-height: 90vh;
  position: relative;
  .followGroupBox {
    width: 100%;
    height: calc(50px + constant(safe-area-inset-bottom));
    height: calc(50px + env(safe-area-inset-bottom));
  }
  .followGroup_btn_box {
    background-color: #fff;
    width: 100%;
    position: absolute;
    left: 0;
    bottom: 0;
    padding-bottom: constant(safe-area-inset-bottom);
	  padding-bottom: env(safe-area-inset-bottom);
    z-index: 30;
    .btn_box {
      width: 100%;
      height: 100rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 0;
      margin: 0;
      font-size: 32rpx;
      background-color: #E44435;
      color: #fff;
      border-radius: 0;
      &.btn_box_dis {
        opacity: 0.7;
      }
    }
    .sold_out_box {
      background-color: #F2F3F5;
      color: #C8C9CC;
    }
  }
  .headTitle {
    line-height: 72rpx;
    box-shadow: inset 0px -1px 0px #eeeeee;
    padding: 0 32rpx;
    background-color: #fff;
  }
  .fictitious_box {
    background-color: #fff;
    border-bottom: 2rpx dashed #E44435;
    margin-bottom: 16rpx;
  }
  .addressBox{
    display: flex;
    align-items: center;
    padding-top: 20rpx;
    padding-bottom: 20rpx;
    border-bottom: 2rpx dashed #E44435;
    margin-bottom: 16rpx;
    background-color: #fff;
    position: relative;
    flex: 1;
    .not_address_box {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #969799;
      font-size: 28rpx;
      padding: 20rpx 0;
      .icon-tianjia {
        font-size: 32rpx;
        color: #969799;
      }
    }
    .addressBox_l {
      flex: 0 0 auto;
      margin-right: 20rpx;
      .icon-address {
        color: #323233;
        font-size: 28rpx;
      }
    }
    .addressBox_r {
      width: 612rpx;
      display: flex;
      flex-flow: column;
      color: #323233;
      justify-content: space-between;
      font-size: 24rpx;
      .addressBox_r_top {
        display: flex;
        flex-wrap: wrap;
      }
      .addressBox_r_bot {
        margin-top: 16rpx;
      }
    }
    .icon-arrow_right {
      position: absolute;
      color: #969799;
      font-size: 28rpx;
      right: 32rpx;
      top: 50%;
      transform: translateY(-50%);
    }
  }
  .goodsBox_two{
    background: #fff;
    width: 100%;
    padding: 0 32rpx;
    border-bottom: 2rpx solid #DCDEE0;
    .u-flex {
      display: flex;
      flex: 1;
    }
    .goodsImg{
      width: 160rpx;
      height: 160rpx;
      border-radius: 8rpx;
      overflow: hidden;
      position: relative;
      margin-right: 32rpx;
      flex: 0 0 auto;
      .img_box {
        width: 100%;
        height: 100%;
      }
      .times{
        position: absolute;
        width: 100%;
        bottom: 0;
        left: 0;
        text-align: center;
        color: #FFF;
        font-size: 20rpx;
        line-height: 40rpx;
        background: rgba(0, 0, 0, 0.4);
      }
    }
    .goodsMsg{
      display: flex;
      flex-flow: column;
      justify-content: space-between;
      height: 160rpx;
      width: 100%;
      .themeFontColor {
        line-height: 48rpx;
      }
      .specs_box {
        display: flex;
        // flex-wrap: wrap;
        align-items: center;
        margin: 16rpx 0;
        padding: 0;
        width: 100%;
        height: 32rpx;
        flex: 1;
        .select_tit_box {
          flex: 0 0 auto;
          width: 96rpx;
        }
        .specs_name_box {
          width: 390rpx;
          height: 32rpx;
          line-height: 32rpx;
          .span {
            display: inline-block;
            .em {
              display: inline-block;
            }
          }
        }
      }
    }
  }
  .goodsBox{
    width: 100%;
    min-height: 30vh;
    max-height: 50vh;
    box-sizing: border-box;
  }
  .color9{
    color: rgba(0, 0, 0, 0.9);
  }
  .goodsScpe{
    padding: 32rpx;
    background-color: #fff;
    box-sizing: border-box;
    .scpeBox_con {
      display: flex;
      flex-wrap: wrap;
    }
    .scpeBox{
      margin-top: 24rpx;
      background: #F2F3F5;
      border-radius: 4rpx;
      color: rgba(0, 0, 0, 0.9);
      height: 48rpx;
      line-height: 48rpx;
      padding: 0rpx 20rpx;
      margin-right: 24rpx;
      min-width: 64rpx;
      &.scpeBox_dis {
        opacity: 0.4;
      }
    }
    .scpeBox.acitveScpe{
      background: #E44435;
      color: #FFF;
    }
  }
  .remarkBox{
    margin: 20rpx 0;
    display: flex;
    align-items: center;
    padding: 24rpx 32rpx;
    line-height: 48rpx;
    background-color: #fff;
  }
}
</style>
